﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chess
{

    public class csPossibleMoveList
    {
        List<csPossibleMove> _possibleMoves = null;

        public csPossibleMoveList()
        {
            this._possibleMoves= new List<csPossibleMove>();
        }

        public void Add(csPossibleMove move)
        {
            this._possibleMoves.Add(move);
        }

        public List<csPossibleMove> GetList
        {
            get { return this._possibleMoves; }
        }

        public csPossibleMove GetMoveWithHighestValue
        {
            get
            {
                csPossibleMove result = _possibleMoves[0];
                int startingEvaluation = result.Evaluation;
                foreach(csPossibleMove move in this._possibleMoves)
                {
                    if (move.Evaluation > result.Evaluation)
                    {
                        result = move;                        
                    }
                }

                if ((this._possibleMoves.Count > 1)&&(result.Evaluation == startingEvaluation))
                {
                    int randomNumber = Tools.rnd.Next(0, this._possibleMoves.Count - 1);
                    result = this._possibleMoves[randomNumber];
                }

                return result;
            }

        }

    }
}
